package com.example.blog.controller.follow;

import com.example.blog.pojo.Result;
import com.example.blog.service.FollowService;
import com.example.blog.util.TokenUtil.GetCookie;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/follows")
public class FollowController {
    @Resource
    private FollowService followService;
    //关注接口
    @PutMapping("/{id}/{isFollow}")
    public Result follow(@PathVariable("id") Long followuserid, @PathVariable("isFollow") String isFollow
            , HttpServletRequest request) {
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return followService.follow(followuserid,isFollow,token);
    }
    //判断用户是否被关注
    @GetMapping("/or/not/{id}")
    public Result follow(@PathVariable("id") Long followuserid, HttpServletRequest request) {
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return followService.isFollow(followuserid,token);
    }
    //获取关注列表
    @GetMapping("/getFollowUsers")
    public Result getFollowUsers(HttpServletRequest request){
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return followService.getFollowUsers(token);
    }
    //获取粉丝列表
    @GetMapping("/getFans")
    public Result getFans(HttpServletRequest request){
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return followService.getFans(token);
    }
    //获取粉丝数
    @GetMapping("/getFansCount")
    public Result<Integer> getFansCount(HttpServletRequest request){
        String cookieValue = request.getHeader("Cookie");
        String token = GetCookie.getCookieValue(cookieValue);
        return followService.getFansCount(token);
    }
}
